package com.lottery.ruok.lottrey.ui.component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.GetPayTypeResponse;
import com.lottery.ruok.lottrey.utils.StringUtils;

import glideHelp.GlideHelper;

/**
 * 充值页面底部ItemView
 */
public class ChargeItemView extends BaseRelativeLayout {

    private ImageView mIconView;
    private TextView mTitleView;
    private TextView mTipView;
    private String title;

    public ChargeItemView(Context context) {
        super(context);
    }

    public ChargeItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ChargeItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(Context context, AttributeSet attrs, int defStyleAttr) {
    }

    @Override
    protected void initView(Context context) {
        LayoutInflater.from(mContext).inflate(R.layout.view_item_charge, this);
        mIconView = findViewById(R.id.iv_icon);
        mTitleView = findViewById(R.id.tv_title);
        mTipView = findViewById(R.id.tv_tip);
    }

    @Override
    protected void load(Context context) {

    }

    public void setData(GetPayTypeResponse.GetPayItemsResponse data) {
/*        switch (title) {
            case "人工通道":
                if ("transfer".equals(data.getName_alias())) {
                    GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                    mTitleView.setText(data.getItem_name());
                    mTipView.setText(data.getDesc());
                } else {
                    GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                    mTitleView.setText(data.getItem_name());
                    mTipView.setText(data.getDesc());
                }
                if (data.getDesc() == null || "".equals(data.getDesc())) {
                    mTipView.setVisibility(GONE);
                } else {
                    mTipView.setVisibility(VISIBLE);
                }
                break;
            case "一键支付":
                GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                mTitleView.setText(data.getItem_name());
                mTipView.setText(data.getDesc());
                if (data.getDesc() == null || "".equals(data.getDesc())) {
                    mTipView.setVisibility(GONE);
                } else {
                    mTipView.setVisibility(VISIBLE);
                }
                break;
            case "快捷扫码":
                GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                mTitleView.setText(data.getItem_name());
                mTipView.setText(data.getDesc());
                if (data.getDesc() == null || "".equals(data.getDesc())) {
                    mTipView.setVisibility(GONE);
                } else {
                    mTipView.setVisibility(VISIBLE);
                }
                break;
        }*/
        if (data.getPayType().equals("MT")) {
            //人工通道改为公司入款
            if ("transfer".equals(data.getName_alias())) {
                GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                mTitleView.setText(data.getItem_name());
                mTipView.setText(data.getDesc());
            } else {
                GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                mTitleView.setText(data.getItem_name());
                mTipView.setText(data.getDesc());
            }
            if (data.getDesc() == null || "".equals(data.getDesc())) {
                mTipView.setVisibility(GONE);
            } else {
                mTipView.setVisibility(VISIBLE);
            }
        }else {
            if (StringUtils.isNotEmpty(data.getRedirects())){
                if (data.getRedirects().equals("0")){
                    //联赢支付
                    GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                    mTitleView.setText(data.getItem_name());
                    mTipView.setText(data.getDesc());
                    if (data.getDesc() == null || "".equals(data.getDesc())) {
                        mTipView.setVisibility(GONE);
                    } else {
                        mTipView.setVisibility(VISIBLE);
                    }
                }else {
                    //扫码支付
                    GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                    mTitleView.setText(data.getItem_name());
                    mTipView.setText(data.getDesc());
                    if (data.getDesc() == null || "".equals(data.getDesc())) {
                        mTipView.setVisibility(GONE);
                    } else {
                        mTipView.setVisibility(VISIBLE);
                    }
                }
            }else {
                //扫码支付
                GlideHelper.loadImage(mContext, data.getLogo(), mIconView);
                mTitleView.setText(data.getItem_name());
                mTipView.setText(data.getDesc());
                if (data.getDesc() == null || "".equals(data.getDesc())) {
                    mTipView.setVisibility(GONE);
                } else {
                    mTipView.setVisibility(VISIBLE);
                }
            }


        }


    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }
}
